import { Component, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute, Params, Router } from '@angular/router';
import { NzMessageService } from 'ng-zorro-antd';
import { CompanyService } from '../../../core/routes-services/company.service';
import { Step2Component } from '../../goods/goods-list/step/step2.component';
import { Step3Component } from '../../goods/goods-list/step/step3.component';
import { Step1Component } from '../../goods/goods-list/step/step1.component';
import { Step1points1Component } from '../step/step1points1.component';

@Component({
  selector: 'app-company-detail',
  templateUrl: './company-detail.component.html',
  styles: [],
})
export class CompanyDetailComponent implements OnInit {

  id: any = 0;// 默认表示新增
  entity: any = {};
  isLoading: boolean = false;

  @ViewChild('step0') step0: Step1Component;
  @ViewChild('step1_1') step1_1: Step1points1Component;
  @ViewChild('step1') step1: Step2Component;
  @ViewChild('step2') step2: Step3Component;

  title: any;

  constructor(
    private router: Router,
    private route: ActivatedRoute,
    public companyService: CompanyService,
    public message: NzMessageService,
  ) {
  }



  ngOnInit() {
    this.companyService.reset();
    this.companyService.entity = this.entity;
    this.title = this.entity.title;
    this.route.queryParams.forEach((params: Params) => {
      this.id = +params['id'];
      this.initEntity();
    });
  }
  indexChange(index) {
    this.companyService.step = index;
  }
  initEntity() {
    this.isLoading = true;
    //默认第一条id=1为 市场营销小程序 招商首页-公司简介
    this.companyService.detail(this.id).then((res) => {
      if (res.status.toString().startsWith('20')) {
        this.entity = res.data;
        this.title = this.entity.title;
        this.companyService.entity = this.entity;
       this.companyService.imgList = res.data.bannerList;
       this.companyService.profitCusList = res.data.profitCusList;
       this.companyService.profitSetting = res.data.profitSetting;
      } else {
        this.message.warning(res.message);
      }
      this.isLoading = false;
    }, error => {
      this.message.error(error.message ? error.message : error.error);
      this.isLoading = false;
    });
  }


}
